package com.usian.controller;


import com.usian.pojo.TbItem;
import com.usian.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class CartServiceController {

    @Autowired
    private CartService cartService;

    /**
     * 从reids中获取购物车
     * @param userId
     * @return
     */
    @RequestMapping("getCartFromRedis")
    public Map<String, TbItem> getCartFromRedis(@RequestParam String userId){
        return cartService.getCartFromRedis(userId);
    }

    /**
     * 将购物车存到redis中
     * @param cart
     * @param userId
     */
    @RequestMapping("addCartToRedis")
    public void addCartToRedis(@RequestBody Map<String, TbItem> cart, @RequestParam String userId){
        cartService.addCartToRedis(cart,userId);
    }
}
